package ducpham.rogueconsole.mark2;

import javax.swing.JFrame;

public class Main extends JFrame {

	private static final long serialVersionUID = 1L;
	private static final int FPS = 20;

	public Main() {
		RConsole rc = new RConsole(48, 24);
		RKeyListener rkl = new RKeyListener(rc);
		add(rc);
		setVisible(true);
		pack();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(true);
		
		while(true){
			try {
				long pre = System.currentTimeMillis();
				rkl.moveCursor();
				rc.repaint();
				long after = System.currentTimeMillis();
				if ((pre - after) < -1000/FPS) Thread.sleep(1);
				else Thread.sleep(1000/FPS + pre - after);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}				
	}

	public static void main(String[] args) {
		new Main();
	}

}
